/**
 * Created by kaki on 2017/4/18.
 */

export let RuleArray = {
  name: [
    { required: true, message: '名称不能为空', trigger: 'blur' }
  ],
  contacts: [
    { required: true, message: '商户联系人名称不能为空', trigger: 'blur' }
  ],
  phone: [
    { required: true, message: '手机号码不能为空', trigger: 'blur' },
    { validator: validatePhone, trigger: 'blur' }
  ],
  city: [
    { required: true, type: 'array', message: '请选择城市', trigger: 'change' }
  ],
  gender: [
    { required: true, message: '请选择性别', trigger: 'change' }
  ],
  interest: [
    { required: true, type: 'array', min: 1, message: '至少选择一个爱好', trigger: 'change' },
    { type: 'array', max: 2, message: '最多选择两个爱好', trigger: 'change' }
  ],
  date: [
    { required: true, type: 'date', message: '请选择日期', trigger: 'change' }
  ],
  time: [
    { required: true, type: 'date', message: '请选择时间', trigger: 'change' }
  ],
  desc: [
    { required: true, message: '详细地址不能位空', trigger: 'blur' }
  ],
  time_limit: [
    { required: true, message: '有效期不能为空', trigger: 'blur' },
    { validator: validateNumber, trigger: 'blur' }
  ],
  number_of_time: [
    { required: true, message: '次数不能为空', trigger: 'blur' },
    { validator: validateNumber, trigger: 'blur' }
  ],
  calssroom_name: [
    { required: true, message: '课室名不能为空', trigger: 'blur' }
  ]
}

/**
 * 手机号码验证
 * @param rule
 * @param value
 * @param callback
 */
function validatePhone (rule, value, callback) {
  if (!(/^1[34578]\d{9}$/.test(value))) {
    callback(new Error('手机号码格式不正确'))
  } else {
    callback()
  }
}

/**
 * 只能输入数字
 * @param rule
 * @param value
 * @param callback
 */
function validateNumber (rule, value, callback) {
  if (!(/^[0-9]*$/.test(value))) {
    callback(new Error('只能输入正整数'))
  } else {
    callback()
  }
}
